<?php 
require_once('../kelas/amankanParam.php');
require_once('../kelas/fungsi.php');
require_once('../kelas/record.php');
require_once('../kelas/pemesanan.php');
require_once('../kelas/kategori.php');
require_once('../kelas/produk.php');
$dtGet = $objParamAman->getMethod();
$dtPost = $objParamAman->postMethod();
$judul = isset($dtGet['idorder'])?"Detail Pesanan Untuk :".$dtGet['idorder']:"Detail Pesanan";
$idO =  isset($dtGet['idorder'])?$dtGet['idorder']:"";
echo $objFungsi->buatJudul($judul);
$dtOrd = $objPemesanan->getDataPesan($idO,null,true);
$dtOrdHeader = $dtOrd['header'];
if($dtOrdHeader['success']==false){
echo	$objFungsi->alert($dtOrdHeader['error_msg']);
}else{
$dtOrdDetail = isset($dtOrd['detail'])?$dtOrd['detail']:array();
?>
<div style="float:left; width:40%">
<h4>No Pesanan</h4>
<p><?php echo $dtOrdHeader["id_pemesanan"] ?></p>
<h4>Nama Pemesan</h4>
<p><?php echo $dtOrdHeader["nama"]; ?></p>
<h4>Kontak Pemesan</h4>
<p><?php echo "Telepon: ".$dtOrdHeader["telepon"].", Email:".$dtOrdHeader['email']; ?></p>
<h4>Nama Penerima</h4>
<p><?php echo $dtOrdHeader["nama_penerima"]; ?></p>
<h4>Tanggal Pemesanan</h4>
<p><?php echo $objFungsi->tanggal1($dtOrdHeader['tanggal']) ?></p>
<h4>Kontak Penerima</h4>
<p><?php echo "Telepon: ".$dtOrdHeader["telepon_penerima"].", Email:".$dtOrdHeader['email_penerima']; ?></p>
<h4>Alamat Penerima</h4>
<p><?php echo $dtOrdHeader['alamat_penerima'] ?></p>
<h4>Kota Penerima</h4>
<p><?php echo $dtOrdHeader['kota_penerima'] ?></p>
<h4>Biaya Pengiriman</h4>
<p><?php echo $objFungsi->formatUang($dtOrdHeader['biaya_ongkir']); ?></p>
<h4>Pesan Tambahan</h4>
<p><?php echo $dtOrdHeader['pesan_tambahan'] ?></p>
<h4>Pembayaran</h4>
<p><?php echo $dtOrdHeader['bank']." | ".$dtOrdHeader['norek']." | ".$dtOrdHeader['cabang'] ?></p>
</div>
<div style="float:right;width:60%">
	<form name="tindakanOrder">
		<table>
			<tr>
				<td>Status</td>
				<td>
					<input type="hidden" name="id" value="<?php echo $dtOrdHeader['id'] ?>" />
					<input type="hidden" name="id_pemesanan" value="<?php echo $dtOrdHeader['id_pemesanan'] ?>" />
					<select name="status_pesan" class="text_box_3">
						<?php echo $objPemesanan->buatComboStatus($dtOrdHeader['status_pesan']); ?>						
					</select>
				</td>
			</tr>
			<tr>
				<td>Keterangan</td>
				<td><textarea name="ket_admin" class="text_box_3"><?php echo $dtOrdHeader['ket_admin'] ?></textarea></td>
			</tr>

			<tr>
				<td colspan="2"><input  type="submit" value="Proses"/></td>
			</tr>
		</table>
	</form>

<div class="frame_table_order">
<table width="100%" cellpadding="5" cellspacing="0" border="1" style="border-collapse:collapse">

    <thead>
        <tr align="center" valign="middle" bgcolor="#CCCCCC">
			<td>gambar</td>
			<td>Nama Produk</td>
			<td>Qty</td>
			<td>Harga Awal</td>
			<td>Diskon</td>
			<td>Harga Bayar</td>
			<td>Subtotal</td>
		</tr>
	</thead>
		<?php
		$totByrBrg = 0;
		 foreach ($dtOrdDetail as $detOrd) {
			?>
			<tr>
				<td><img class="gambar-produk-cart" src="<?php echo BASEURL.'produk/'.$detOrd['gambar'] ?>"></td>
				<td><?php echo $detOrd['nama']; ?></td>
				<td><?php echo $detOrd['jumlah_buy'] ?></td>
				<td><?php echo $objFungsi->formatUang($detOrd['harga_awal']) ?></td>
				<td><?php echo $detOrd['diskon'];?></td>
				<td><?php $totByrBrg +=$detOrd['harga_bayar']*$detOrd['jumlah_buy'] ;echo $objFungsi->formatUang($detOrd['harga_bayar']) ?></td>
				<td><?php echo $objFungsi->formatUang($detOrd['harga_bayar']*$detOrd['jumlah_buy']) ?></td>
			</tr>
			<?php

		} 
		?>
	</table>
</div>
	<h3>Total Belanja:</h3>
	<p><?php echo $objFungsi->formatUang($totByrBrg); ?></p>
	<h2>Jumlah Tagihan</h2>
	<p style="color:red;font-weight:bold">	<?php echo $objFungsi->formatUang($totByrBrg+$dtOrdHeader['biaya_ongkir']);  ?></p>
	<?php 
}
//$objFungsi->var_dump($dtOrdHeader,false);
	 ?>
</div>
<script type="text/javascript">
	$(document).ready(function(){
		var frmProses= $(document).find('form[name="tindakanOrder"]');
		frmProses.submit(function(e){
			var dataF = frmProses.serialize();
			var statP = frmProses.find('select[name="status_pesan"]').val();
			var ketADM = frmProses.find('textarea[name="ket_admin"]').val();
			console.log(statP);
			if(statP=='DITOLAK' && ketADM.length==0){
				alert("Silahkan isi keterangan penolakan");
			}else{
				$.ajax({
					url:baseUrl+'proses/pemesanan.php?on=proses',
					data:dataF,
					dataType:'JSON',
					type:'POST',
					success:function(res){
						document.location = baseUrlAdmin+'?v=transaksi&p=order'
					},
					error:function(res){
						alert("Gagal memproses pemesanan, Silahkan coba lagi.");
					}
				});
			}
			e.preventDefault();
		});
	});
</script>